﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BingMapsSample.Components;

namespace BingMapsSample
{
    public partial class ucSearchForm : BaseControl
    {
        //------// Properties \\--------------------------------------------\\
        private Default _parentPage = null;
        public Default ParentPage
        {
            get
            {
                if (_parentPage == null)
                {
                    _parentPage = (Default)base.Page;
                }

                return _parentPage;
            }
        }
        //------\\ Properties //--------------------------------------------//



        //------// Constructors \\------------------------------------------\\
        public ucSearchForm()
        { }
        //------\\ Constructors //------------------------------------------//



        //------// Methods \\-----------------------------------------------\\
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!ParentPage.IsPostBack && ParentPage.SearchIsActive)
            {
                txtKeyword.Value = ParentPage.Keyword;
            }
        }



        #region "Event Handlers"

        protected void btnSearch_Click(object sender, EventArgs args)
        {
            base.Page.Validate("Keyword");

            if (base.Page.IsValid)
            {
                base.Response.Redirect("Default.aspx?keyword=" + HttpUtility.HtmlEncode(txtKeyword.Value.Trim()), false);
                base.SearchResultsController.ClearSearchResults();

                return;
            }
        }

        #endregion
        //------\\ Methods //-----------------------------------------------//
    }
}